package net.lc7.proto;

import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Id;
import org.apache.zookeeper.data.Stat;
import org.apache.zookeeper.server.auth.DigestAuthenticationProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.charset.StandardCharsets;
import java.security.acl.Acl;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Author: Jason.zhu
 * @Create: 2019/05/16 16:19
 */

public class ProtoClient {
    static Logger logger = LoggerFactory.getLogger(ProtoClient.class);

    public static void main(String[] args) throws Exception{


        ZooKeeper zooKeeper = ZKConnect.getZooKeeper();


        /*ZooKeeper zooKeeper = new ZooKeeper("192.168.19.22:2181", 10000, (WatchedEvent watchedEvent) -> {
            logger.warn("触发了[" + watchedEvent.getType().name()+"]事件");
        });*/

        logger.warn("连接状态：{}", zooKeeper.getState());


        //添加节点
        zooKeeper.create("/rootPath", "rootPathData".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

        //读取节点
        System.out.println(new String(zooKeeper.getData("/rootPath",true, null)));

        //修改节点值
        zooKeeper.setData("/rootPath", "rootPathDataNew".getBytes(), 0);

        System.out.println(new String(zooKeeper.getData("/rootPath",true, null)));

        logger.warn("连接状态：{}", zooKeeper.getState());

        //删除节点
        zooKeeper.delete("/rootPath",1);



//        Thread.sleep(5000);

        System.out.println("=====================================");

        zooKeeper.close();
        logger.warn("连接状态：{}", zooKeeper.getState());


        //权限



    }
}
